
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Function;
import cn.edu.scau.cmi.hombio.domain.Role;
import cn.edu.scau.cmi.hombio.domain.RoleAuthority;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class RoleAuthorityServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected RoleAuthorityService service;

	/**
	 * Instantiates a new RoleAuthorityServiceTest.
	 *
	 */
	public RoleAuthorityServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Delete an existing RoleAuthority entity
	* 
	 */
	@Test
	public void deleteRoleAuthority() {
		// TODO: JUnit - Populate test inputs for operation: deleteRoleAuthority 
		RoleAuthority roleauthority = new cn.edu.scau.cmi.hombio.domain.RoleAuthority();
		service.deleteRoleAuthority(roleauthority);
	}

	/**
	 * Operation Unit Test
	* Return a count of all RoleAuthority entity
	* 
	 */
	@Test
	public void countRoleAuthoritys() {
		Integer response = null;
		response = service.countRoleAuthoritys();
		// TODO: JUnit - Add assertions to test outputs of operation: countRoleAuthoritys
	}

	/**
	 * Operation Unit Test
	* Load an existing RoleAuthority entity
	* 
	 */
	@Test
	public void loadRoleAuthoritys() {
		Set<RoleAuthority> response = null;
		response = service.loadRoleAuthoritys();
		// TODO: JUnit - Add assertions to test outputs of operation: loadRoleAuthoritys
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findRoleAuthorityByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findRoleAuthorityByPrimaryKey 
		Integer id = 0;
		RoleAuthority response = null;
		response = service.findRoleAuthorityByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findRoleAuthorityByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Save an existing Role entity
	* 
	 */
	@Test
	public void saveRoleAuthorityRole() {
		// TODO: JUnit - Populate test inputs for operation: saveRoleAuthorityRole 
		Integer id_1 = 0;
		Role related_role = new cn.edu.scau.cmi.hombio.domain.Role();
		RoleAuthority response = null;
		response = service.saveRoleAuthorityRole(id_1, related_role);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRoleAuthorityRole
	}

	/**
	 * Operation Unit Test
	* Delete an existing Role entity
	* 
	 */
	@Test
	public void deleteRoleAuthorityRole() {
		// TODO: JUnit - Populate test inputs for operation: deleteRoleAuthorityRole 
		Integer roleauthority_id = 0;
		Integer related_role_id = 0;
		RoleAuthority response = null;
		response = service.deleteRoleAuthorityRole(roleauthority_id, related_role_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRoleAuthorityRole
	}

	/**
	 * Operation Unit Test
	* Return all RoleAuthority entity
	* 
	 */
	@Test
	public void findAllRoleAuthoritys() {
		// TODO: JUnit - Populate test inputs for operation: findAllRoleAuthoritys 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<RoleAuthority> response = null;
		response = service.findAllRoleAuthoritys(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllRoleAuthoritys
	}

	/**
	 * Operation Unit Test
	* Delete an existing Function entity
	* 
	 */
	@Test
	public void deleteRoleAuthorityFunction() {
		// TODO: JUnit - Populate test inputs for operation: deleteRoleAuthorityFunction 
		Integer roleauthority_id_1 = 0;
		Integer related_function_id = 0;
		RoleAuthority response = null;
		response = service.deleteRoleAuthorityFunction(roleauthority_id_1, related_function_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRoleAuthorityFunction
	}

	/**
	 * Operation Unit Test
	* Save an existing RoleAuthority entity
	* 
	 */
	@Test
	public void saveRoleAuthority() {
		// TODO: JUnit - Populate test inputs for operation: saveRoleAuthority 
		RoleAuthority roleauthority_1 = new cn.edu.scau.cmi.hombio.domain.RoleAuthority();
		service.saveRoleAuthority(roleauthority_1);
	}

	/**
	 * Operation Unit Test
	* Save an existing Function entity
	* 
	 */
	@Test
	public void saveRoleAuthorityFunction() {
		// TODO: JUnit - Populate test inputs for operation: saveRoleAuthorityFunction 
		Integer id_2 = 0;
		Function related_function = new cn.edu.scau.cmi.hombio.domain.Function();
		RoleAuthority response = null;
		response = service.saveRoleAuthorityFunction(id_2, related_function);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRoleAuthorityFunction
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
